
using System;

using PolePosition.v3.EntityFactory;
using PolePosition.v3.EntityLibrary;

namespace PolePosition.v3.EntityFactory
{
    /// <summary>
    /// 
    /// </summary>
	/// <remarks></remarks>
	public sealed partial class VendorDistributionPoleFactory 
	{		
		/// <summary>
		/// This static constructor is responsible for subscribing to all events in the class. 
		/// If Child Collections were created, then this constructor subscribes to events 
		/// that handle getting and saving child collections.
		/// </summary>
        /// <remarks><para>This constructor is present in VendorDistributionPoleFactory because VendorDistributionPole Entities
        /// have Child Collection properties. Child Collection properties contain groups of additional Entities
        /// that in turn, contain data related to VendorDistributionPole Entities. Whether Child Collections, this 
        /// constructor, and the event handlers it wires up are present was determined at the time this code was
        /// generated. See the documentation for the <see cref="Classes.Entities.VendorDistributionPoleEntity" /> for more.
        /// </para>
        /// <para>This constructor makes sure that all actions by the Factory that are relevant to Child Collections
        /// are responded to. This means subscribing to the events raised by any of the <c>Save()</c>, 
        /// <c>GetEntity()</c> and <c>GetCollection()</c> overloads (see the documentation for
        /// <see cref="Classes.Factories.VendorDistributionPoleFactory"/>). The event handlers assigned by this constructor
        /// ensure that Child Collections are properly retrieved, saved, or deleted (that is, preventing any concurrency
		/// violations) whenever the VendorDistributionPoleEntity they belong to is modified.</para>
        /// <para>This constructor assigns handlers to the following VendorDistributionPoleFactory
        /// events:</para>
        /// <list type="bullet">
            /// <item>"Get" events: <see cref="VendorDistributionPoleFactory.OnAfterGetEntity" /> and 
            /// <see cref="VendorDistributionPoleFactory.OnAfterGetEntityCollection" />. This ensures that when a 
            /// VendorDistributionPoleEntity is retrieved from the database, any Child Collections it needs are retrieved also.
            /// </item>
            /// 
            /// <item>"Save" events: <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />, 
            /// <see cref="VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />, and 
            /// <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />. 
            /// Since transactions are used when saving Entities, subscription to the first two
            /// events ensures that only one transaction is started and that it is commited by the correct Factory 
            /// <c>Save()</c> method (see how the 
            /// <see cref="Classes.Factories.VendorDistributionPoleFactory.Save(Classes.Entities.VendorDistributionPoleEntity, bool)"/>
            /// method works).<para></para>
            /// Subscription to the third event ensures that when a VendorDistributionPoleEntity is saved, any Child Collections
            /// it contains are also saved and that they are saved in the correct order to avoid concurrency problems.
            /// </item>
            /// 
            /// <item>"Delete" events: <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />. This ensures that when
            /// a VendorDistributionPoleEntity is deleted, any Child Collections it contains are deleted first to avoid concurrency
			/// problems.
            /// </item>
        /// </list>
        /// <para>One event handler is assigned to each event for every Child Collection that needs to be present
        /// for a VendorDistributionPoleEntity. So, if the Entity has two Child Collections, two handlers are added to 
        /// each event; in that way, all collections will react when an event is raised. This constructor assigns
		/// handlers for:
		/// <list type="bullet">
        /// </list>
        /// </para>
		/// <para>Handler methods were generated for each event and for each collection type, and are also part
		/// of the VendorDistributionPoleFactory (they are all identified by a composed name that consists of: the
		/// event they respond to, the child collection they belong to, and the word "Handler" at the end.</para>
		/// <para>Note also that this constructor calls the 
		/// <see cref="Classes.Factories.VendorDistributionPoleFactory.CustomConstructor()"/> method at the end. Since
		/// code for that method is not generated by the code generation tool that generated this constructor, 
		/// calling that method allows for custom code to execute along with this constructor.</para>
        /// </remarks>
        static void ChildCollectionConstructor()
        {
			#region Wire Up Event Handling for VendorDistributionImage Child Collection
			//Get Methods - wire up the get events so that when the parent class is 
			//aquired the children are also
            VendorDistributionPoleFactory.OnAfterGetEntity += VendorDistributionPoleFactory.OnAfterGetVendorDistributionImageEntityHandler;
            VendorDistributionPoleFactory.OnAfterGetEntityCollection += VendorDistributionPoleFactory.OnAfterGetVendorDistributionImageCollectionHandler;

            //Collection Save
            VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionImageCollectionBeginHandler;

            //Entity Save
            VendorDistributionPoleFactory.OnBeforeSaveEntityBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionImageEntityBeginHandler;
            VendorDistributionPoleFactory.OnBeforeSaveEntityCommit += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionImageEntityCommitHandler;

            //Entity Delete
            VendorDistributionPoleFactory.OnBeforeEntityDelete += VendorDistributionPoleFactory.OnBeforeVendorDistributionImageEntityDeleteHandler;
			#endregion
		
			#region Wire Up Event Handling for VendorDistributionMeter Child Collection
			//Get Methods - wire up the get events so that when the parent class is 
			//aquired the children are also
            VendorDistributionPoleFactory.OnAfterGetEntity += VendorDistributionPoleFactory.OnAfterGetVendorDistributionMeterEntityHandler;
            VendorDistributionPoleFactory.OnAfterGetEntityCollection += VendorDistributionPoleFactory.OnAfterGetVendorDistributionMeterCollectionHandler;

            //Collection Save
            VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionMeterCollectionBeginHandler;

            //Entity Save
            VendorDistributionPoleFactory.OnBeforeSaveEntityBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionMeterEntityBeginHandler;
            VendorDistributionPoleFactory.OnBeforeSaveEntityCommit += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionMeterEntityCommitHandler;

            //Entity Delete
            VendorDistributionPoleFactory.OnBeforeEntityDelete += VendorDistributionPoleFactory.OnBeforeVendorDistributionMeterEntityDeleteHandler;
			#endregion
		
			#region Wire Up Event Handling for VendorDistributionRecloser Child Collection
			//Get Methods - wire up the get events so that when the parent class is 
			//aquired the children are also
            VendorDistributionPoleFactory.OnAfterGetEntity += VendorDistributionPoleFactory.OnAfterGetVendorDistributionRecloserEntityHandler;
            VendorDistributionPoleFactory.OnAfterGetEntityCollection += VendorDistributionPoleFactory.OnAfterGetVendorDistributionRecloserCollectionHandler;

            //Collection Save
            VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionRecloserCollectionBeginHandler;

            //Entity Save
            VendorDistributionPoleFactory.OnBeforeSaveEntityBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionRecloserEntityBeginHandler;
            VendorDistributionPoleFactory.OnBeforeSaveEntityCommit += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionRecloserEntityCommitHandler;

            //Entity Delete
            VendorDistributionPoleFactory.OnBeforeEntityDelete += VendorDistributionPoleFactory.OnBeforeVendorDistributionRecloserEntityDeleteHandler;
			#endregion
		
			#region Wire Up Event Handling for VendorDistributionInspectionResult Child Collection
			//Get Methods - wire up the get events so that when the parent class is 
			//aquired the children are also
            VendorDistributionPoleFactory.OnAfterGetEntity += VendorDistributionPoleFactory.OnAfterGetVendorDistributionInspectionResultEntityHandler;
            VendorDistributionPoleFactory.OnAfterGetEntityCollection += VendorDistributionPoleFactory.OnAfterGetVendorDistributionInspectionResultCollectionHandler;

            //Collection Save
            VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionInspectionResultCollectionBeginHandler;

            //Entity Save
            VendorDistributionPoleFactory.OnBeforeSaveEntityBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionInspectionResultEntityBeginHandler;
            VendorDistributionPoleFactory.OnBeforeSaveEntityCommit += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionInspectionResultEntityCommitHandler;

            //Entity Delete
            VendorDistributionPoleFactory.OnBeforeEntityDelete += VendorDistributionPoleFactory.OnBeforeVendorDistributionInspectionResultEntityDeleteHandler;
			#endregion
		
			#region Wire Up Event Handling for VendorDistributionSectionalizer Child Collection
			//Get Methods - wire up the get events so that when the parent class is 
			//aquired the children are also
            VendorDistributionPoleFactory.OnAfterGetEntity += VendorDistributionPoleFactory.OnAfterGetVendorDistributionSectionalizerEntityHandler;
            VendorDistributionPoleFactory.OnAfterGetEntityCollection += VendorDistributionPoleFactory.OnAfterGetVendorDistributionSectionalizerCollectionHandler;

            //Collection Save
            VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionSectionalizerCollectionBeginHandler;

            //Entity Save
            VendorDistributionPoleFactory.OnBeforeSaveEntityBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionSectionalizerEntityBeginHandler;
            VendorDistributionPoleFactory.OnBeforeSaveEntityCommit += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionSectionalizerEntityCommitHandler;

            //Entity Delete
            VendorDistributionPoleFactory.OnBeforeEntityDelete += VendorDistributionPoleFactory.OnBeforeVendorDistributionSectionalizerEntityDeleteHandler;
			#endregion
		
			#region Wire Up Event Handling for VendorDistributionTransformer Child Collection
			//Get Methods - wire up the get events so that when the parent class is 
			//aquired the children are also
            VendorDistributionPoleFactory.OnAfterGetEntity += VendorDistributionPoleFactory.OnAfterGetVendorDistributionTransformerEntityHandler;
            VendorDistributionPoleFactory.OnAfterGetEntityCollection += VendorDistributionPoleFactory.OnAfterGetVendorDistributionTransformerCollectionHandler;

            //Collection Save
            VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionTransformerCollectionBeginHandler;

            //Entity Save
            VendorDistributionPoleFactory.OnBeforeSaveEntityBegin += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionTransformerEntityBeginHandler;
            VendorDistributionPoleFactory.OnBeforeSaveEntityCommit += VendorDistributionPoleFactory.OnBeforeSaveVendorDistributionTransformerEntityCommitHandler;

            //Entity Delete
            VendorDistributionPoleFactory.OnBeforeEntityDelete += VendorDistributionPoleFactory.OnBeforeVendorDistributionTransformerEntityDeleteHandler;
			#endregion
		
		}
		
		#region Event Handlers: VendorDistributionImage 
		
		/// <summary>
        /// Stores the number that indicates the order of the VendorDistributionImage table in the
		/// DataSet returned by the Factory's <c>Get()</c> methods. 
        /// </summary>
		/// <remarks>This number is used by the <see cref="OnAfterGetVendorDistributionImageEntityHandler" />
		/// and the <see cref="OnAfterGetVendorDistributionImageCollectionHandler" /> methods to determine
		/// if the VendorDistributionImage table exists in the DataSet. This number was
		/// determined at the time the code was generated.
		/// </remarks>
		private const int VendorDistributionImageOrdinalPosition = 1;
		
		#region Get VendorDistributionImage Event Handlers

		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntity" /> event. Fills a collection 
		/// with <c>VendorDistributionImage</c> Entities and adds it to the VendorDistributionPoleEntity passed in the event
		/// argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionImage
		/// table from which the VendorDistributionImage Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entity to which the collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> using data from the 
		/// DataSet passed in the event argument and then assigns it to the
		/// <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionImageCollection" /> property of the
		/// VendorDistributionPoleEntity being retrieved (also passed in the event argument).</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionImageEntityHandler(object sender, Classes.Bases.AfterGetEntityEventArgs args)
        {

            //ensure that the dataset contains the second datatable constaining
            //the VendorDistributionImage data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionImageOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionImage not available for addition to VendorDistributionPole entity; The factory event handler found that there is no member ordinally placed in the dataset datatable collection."));
            }


            //redeclare and cast the argument result entity 
            VendorDistributionPoleEntity EntityToReturn;
            EntityToReturn = (VendorDistributionPoleEntity)args.EntityToReturn;

			//ensure the entity is created
			if (EntityToReturn == null)
				return;

            //create an object to generate the collection for addition
            //to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionImageEntity> NewCollection;

            //fill the collection with the datatable
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionImageEntity>(args.DataSetFromDataBase.Tables[VendorDistributionImageOrdinalPosition],args.UseCheckSum);

            //add the collection to the entity
            EntityToReturn.VendorDistributionImageCollection = NewCollection;

        }
		
		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntityCollection" /> event. Adds a collection 
		/// of <c>VendorDistributionImage</c> Entities to each VendorDistributionPoleEntity in the collection passed in the 
		/// event argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionImage
		/// table from which the VendorDistributionImage Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entities to which a VendorDistributionImage collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> and fills it with VendorDistributionImage
		/// Entities from the VendorDistributionImage data contained in the DataSet passed in the event argument. It then filters
		/// this collection for each VendorDistributionPoleEntity (according to the Vendor_Distribution_Poles_PoleId
		/// property), and assigns the result to the <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionImageCollection" />
		/// property of each VendorDistributionPoleEntity.</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionImageCollectionHandler(object sender, Classes.Bases.AfterGetEntityCollectionEventArgs args)
        {
            //ensure that the dataset contains the second datatable constaining
            //the Document Tracking notes data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionImageOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionImage not available for addition to VendorDistributionPole entity."));
            }


            //create an object to hold the collection for addition to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionImageEntity> NewCollection;
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionImageEntity>(args.DataSetFromDataBase.Tables[1],args.UseCheckSum);


            //redeclare and cast the argument result colection
            ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity> ResultCollection;
            ResultCollection = (ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity>)args.CollectionToReturn;


            //loop through each entity in the resulting collection
            foreach (VendorDistributionPoleEntity ParentEntity in ResultCollection)
            {
                //create an entity that will be used to filter
                VendorDistributionImageEntity filterEntity = new VendorDistributionImageEntity();
                filterEntity.Vendor_Distribution_PoleFk = ParentEntity.Vendor_Distribution_Poles_PoleId;


                //create a filtered collection and add it to the entity
                ParentEntity.VendorDistributionImageCollection = NewCollection.Filter(filterEntity, ProjectCommon2.Enumerations.FilterOperator.And);

            }

        }

        #endregion
		
        #region Start VendorDistributionImage Transactions Event Handlers
		
		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionImageCollectionBeginHandler(object sender, Classes.Bases.BeforeSaveCollectionBeginEventArgs args)
        {

            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }

        }

		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionImageEntityBeginHandler(object sender, Classes.Bases.BeforeSaveEntityBeginEventArgs args)
        {
            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }
        }

        #endregion

		#region Insert/Update/Delete VendorDistributionImage Event Handlers
		
		/// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />
		/// event. Responsible for deleting all child VendorDistributionImage Entities from the database before the 
		/// parent VendorDistributionPoleEntity is deleted.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeEntityDeleteEventArgs" />.</param>
		/// <remarks>
		/// <para>Sets the deletion mark for every VendorDistributionImageEntity in the child collection to
		/// <c>true</c> by calling the collection's 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;.SetAllIsMarkedToDelete(bool)" /> method.
		/// Then it deletes the collection by sending it to the VendorDistributionImageFactory's
		/// <see cref="Factories.VendorDistributionImageFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionImageEntity&gt;, bool)" />
		/// method.</para>
		/// </remarks>
        static void OnBeforeVendorDistributionImageEntityDeleteHandler(object sender, Classes.Bases.BeforeEntityDeleteEventArgs args)
        {

			//redeclare and cast the argument delete entity
            VendorDistributionPoleEntity DeleteEntity;
            DeleteEntity = (VendorDistributionPoleEntity)args.EntityToDelete;

			//make sure the child collection is actually used
			if (DeleteEntity.VendorDistributionImageCollection == null)
				return;

            //mark all child entities of the parent entity to delete
            DeleteEntity.VendorDistributionImageCollection.SetAllIsMarkedToDelete(true);

            //delete all the notes
            VendorDistributionImageFactory.Save(DeleteEntity.VendorDistributionImageCollection, args.UseCheckSum);

        }

        /// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />
		/// event. Responsible for saving (which may mean inserting/updating/deleting) all child VendorDistributionImage Entities
		/// to the database before the parent VendorDistributionPoleEntity is saved.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveEntityCommitEventArgs" />.</param>
		/// <remarks>
		/// <para>Saves every VendorDistributionImageEntity in the child collection by sending it to the VendorDistributionImageFactory's
		/// <see cref="Factories.VendorDistributionImageFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionImageEntity&gt;, bool)" />
		/// method.
		/// </para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionImageEntityCommitHandler(object sender, Classes.Bases.BeforeSaveEntityCommitEventArgs args)
        {

			//redeclare and cast the argument save entity
            VendorDistributionPoleEntity EntityToSave;
            EntityToSave = (VendorDistributionPoleEntity)args.EntityToSave;

			//make sure the child collection is actually used
			if (EntityToSave.VendorDistributionImageCollection == null)
				return;


            // loop through each entity in the VendorDistributionImage collection
            foreach (VendorDistributionImageEntity ChildEntity in EntityToSave.VendorDistributionImageCollection)
            {
                //For Saftey set the FK for all the child entities
				ChildEntity.Vendor_Distribution_PoleFk = EntityToSave.Vendor_Distribution_Poles_PoleId;
				

            }

            // insert/update/delete all the child eities
            VendorDistributionImageFactory.Save(EntityToSave.VendorDistributionImageCollection, args.UseCheckSum);

        }

        #endregion
		
 		#endregion
		
		#region Event Handlers: VendorDistributionMeter 
		
		/// <summary>
        /// Stores the number that indicates the order of the VendorDistributionMeter table in the
		/// DataSet returned by the Factory's <c>Get()</c> methods. 
        /// </summary>
		/// <remarks>This number is used by the <see cref="OnAfterGetVendorDistributionMeterEntityHandler" />
		/// and the <see cref="OnAfterGetVendorDistributionMeterCollectionHandler" /> methods to determine
		/// if the VendorDistributionMeter table exists in the DataSet. This number was
		/// determined at the time the code was generated.
		/// </remarks>
		private const int VendorDistributionMeterOrdinalPosition = 2;
		
		#region Get VendorDistributionMeter Event Handlers

		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntity" /> event. Fills a collection 
		/// with <c>VendorDistributionMeter</c> Entities and adds it to the VendorDistributionPoleEntity passed in the event
		/// argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionMeter
		/// table from which the VendorDistributionMeter Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entity to which the collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> using data from the 
		/// DataSet passed in the event argument and then assigns it to the
		/// <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionMeterCollection" /> property of the
		/// VendorDistributionPoleEntity being retrieved (also passed in the event argument).</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionMeterEntityHandler(object sender, Classes.Bases.AfterGetEntityEventArgs args)
        {

            //ensure that the dataset contains the second datatable constaining
            //the VendorDistributionMeter data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionMeterOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionMeter not available for addition to VendorDistributionPole entity; The factory event handler found that there is no member ordinally placed in the dataset datatable collection."));
            }


            //redeclare and cast the argument result entity 
            VendorDistributionPoleEntity EntityToReturn;
            EntityToReturn = (VendorDistributionPoleEntity)args.EntityToReturn;

			//ensure the entity is created
			if (EntityToReturn == null)
				return;

            //create an object to generate the collection for addition
            //to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionMeterEntity> NewCollection;

            //fill the collection with the datatable
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionMeterEntity>(args.DataSetFromDataBase.Tables[VendorDistributionMeterOrdinalPosition],args.UseCheckSum);

            //add the collection to the entity
            EntityToReturn.VendorDistributionMeterCollection = NewCollection;

        }
		
		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntityCollection" /> event. Adds a collection 
		/// of <c>VendorDistributionMeter</c> Entities to each VendorDistributionPoleEntity in the collection passed in the 
		/// event argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionMeter
		/// table from which the VendorDistributionMeter Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entities to which a VendorDistributionMeter collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> and fills it with VendorDistributionMeter
		/// Entities from the VendorDistributionMeter data contained in the DataSet passed in the event argument. It then filters
		/// this collection for each VendorDistributionPoleEntity (according to the Vendor_Distribution_Poles_PoleId
		/// property), and assigns the result to the <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionMeterCollection" />
		/// property of each VendorDistributionPoleEntity.</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionMeterCollectionHandler(object sender, Classes.Bases.AfterGetEntityCollectionEventArgs args)
        {
            //ensure that the dataset contains the second datatable constaining
            //the Document Tracking notes data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionMeterOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionMeter not available for addition to VendorDistributionPole entity."));
            }


            //create an object to hold the collection for addition to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionMeterEntity> NewCollection;
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionMeterEntity>(args.DataSetFromDataBase.Tables[2],args.UseCheckSum);


            //redeclare and cast the argument result colection
            ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity> ResultCollection;
            ResultCollection = (ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity>)args.CollectionToReturn;


            //loop through each entity in the resulting collection
            foreach (VendorDistributionPoleEntity ParentEntity in ResultCollection)
            {
                //create an entity that will be used to filter
                VendorDistributionMeterEntity filterEntity = new VendorDistributionMeterEntity();
                filterEntity.Vendor_Distribution_PoleFk = ParentEntity.Vendor_Distribution_Poles_PoleId;


                //create a filtered collection and add it to the entity
                ParentEntity.VendorDistributionMeterCollection = NewCollection.Filter(filterEntity, ProjectCommon2.Enumerations.FilterOperator.And);

            }

        }

        #endregion
		
        #region Start VendorDistributionMeter Transactions Event Handlers
		
		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionMeterCollectionBeginHandler(object sender, Classes.Bases.BeforeSaveCollectionBeginEventArgs args)
        {

            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }

        }

		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionMeterEntityBeginHandler(object sender, Classes.Bases.BeforeSaveEntityBeginEventArgs args)
        {
            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }
        }

        #endregion

		#region Insert/Update/Delete VendorDistributionMeter Event Handlers
		
		/// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />
		/// event. Responsible for deleting all child VendorDistributionMeter Entities from the database before the 
		/// parent VendorDistributionPoleEntity is deleted.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeEntityDeleteEventArgs" />.</param>
		/// <remarks>
		/// <para>Sets the deletion mark for every VendorDistributionMeterEntity in the child collection to
		/// <c>true</c> by calling the collection's 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;.SetAllIsMarkedToDelete(bool)" /> method.
		/// Then it deletes the collection by sending it to the VendorDistributionMeterFactory's
		/// <see cref="Factories.VendorDistributionMeterFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionMeterEntity&gt;, bool)" />
		/// method.</para>
		/// </remarks>
        static void OnBeforeVendorDistributionMeterEntityDeleteHandler(object sender, Classes.Bases.BeforeEntityDeleteEventArgs args)
        {

			//redeclare and cast the argument delete entity
            VendorDistributionPoleEntity DeleteEntity;
            DeleteEntity = (VendorDistributionPoleEntity)args.EntityToDelete;

			//make sure the child collection is actually used
			if (DeleteEntity.VendorDistributionMeterCollection == null)
				return;

            //mark all child entities of the parent entity to delete
            DeleteEntity.VendorDistributionMeterCollection.SetAllIsMarkedToDelete(true);

            //delete all the notes
            VendorDistributionMeterFactory.Save(DeleteEntity.VendorDistributionMeterCollection, args.UseCheckSum);

        }

        /// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />
		/// event. Responsible for saving (which may mean inserting/updating/deleting) all child VendorDistributionMeter Entities
		/// to the database before the parent VendorDistributionPoleEntity is saved.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveEntityCommitEventArgs" />.</param>
		/// <remarks>
		/// <para>Saves every VendorDistributionMeterEntity in the child collection by sending it to the VendorDistributionMeterFactory's
		/// <see cref="Factories.VendorDistributionMeterFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionMeterEntity&gt;, bool)" />
		/// method.
		/// </para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionMeterEntityCommitHandler(object sender, Classes.Bases.BeforeSaveEntityCommitEventArgs args)
        {

			//redeclare and cast the argument save entity
            VendorDistributionPoleEntity EntityToSave;
            EntityToSave = (VendorDistributionPoleEntity)args.EntityToSave;

			//make sure the child collection is actually used
			if (EntityToSave.VendorDistributionMeterCollection == null)
				return;


            // loop through each entity in the VendorDistributionMeter collection
            foreach (VendorDistributionMeterEntity ChildEntity in EntityToSave.VendorDistributionMeterCollection)
            {
                //For Saftey set the FK for all the child entities
				ChildEntity.Vendor_Distribution_PoleFk = EntityToSave.Vendor_Distribution_Poles_PoleId;
				

            }

            // insert/update/delete all the child eities
            VendorDistributionMeterFactory.Save(EntityToSave.VendorDistributionMeterCollection, args.UseCheckSum);

        }

        #endregion
		
 		#endregion
		
		#region Event Handlers: VendorDistributionRecloser 
		
		/// <summary>
        /// Stores the number that indicates the order of the VendorDistributionRecloser table in the
		/// DataSet returned by the Factory's <c>Get()</c> methods. 
        /// </summary>
		/// <remarks>This number is used by the <see cref="OnAfterGetVendorDistributionRecloserEntityHandler" />
		/// and the <see cref="OnAfterGetVendorDistributionRecloserCollectionHandler" /> methods to determine
		/// if the VendorDistributionRecloser table exists in the DataSet. This number was
		/// determined at the time the code was generated.
		/// </remarks>
		private const int VendorDistributionRecloserOrdinalPosition = 3;
		
		#region Get VendorDistributionRecloser Event Handlers

		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntity" /> event. Fills a collection 
		/// with <c>VendorDistributionRecloser</c> Entities and adds it to the VendorDistributionPoleEntity passed in the event
		/// argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionRecloser
		/// table from which the VendorDistributionRecloser Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entity to which the collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> using data from the 
		/// DataSet passed in the event argument and then assigns it to the
		/// <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionRecloserCollection" /> property of the
		/// VendorDistributionPoleEntity being retrieved (also passed in the event argument).</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionRecloserEntityHandler(object sender, Classes.Bases.AfterGetEntityEventArgs args)
        {

            //ensure that the dataset contains the second datatable constaining
            //the VendorDistributionRecloser data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionRecloserOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionRecloser not available for addition to VendorDistributionPole entity; The factory event handler found that there is no member ordinally placed in the dataset datatable collection."));
            }


            //redeclare and cast the argument result entity 
            VendorDistributionPoleEntity EntityToReturn;
            EntityToReturn = (VendorDistributionPoleEntity)args.EntityToReturn;

			//ensure the entity is created
			if (EntityToReturn == null)
				return;

            //create an object to generate the collection for addition
            //to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionRecloserEntity> NewCollection;

            //fill the collection with the datatable
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionRecloserEntity>(args.DataSetFromDataBase.Tables[VendorDistributionRecloserOrdinalPosition],args.UseCheckSum);

            //add the collection to the entity
            EntityToReturn.VendorDistributionRecloserCollection = NewCollection;

        }
		
		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntityCollection" /> event. Adds a collection 
		/// of <c>VendorDistributionRecloser</c> Entities to each VendorDistributionPoleEntity in the collection passed in the 
		/// event argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionRecloser
		/// table from which the VendorDistributionRecloser Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entities to which a VendorDistributionRecloser collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> and fills it with VendorDistributionRecloser
		/// Entities from the VendorDistributionRecloser data contained in the DataSet passed in the event argument. It then filters
		/// this collection for each VendorDistributionPoleEntity (according to the Vendor_Distribution_Poles_PoleId
		/// property), and assigns the result to the <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionRecloserCollection" />
		/// property of each VendorDistributionPoleEntity.</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionRecloserCollectionHandler(object sender, Classes.Bases.AfterGetEntityCollectionEventArgs args)
        {
            //ensure that the dataset contains the second datatable constaining
            //the Document Tracking notes data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionRecloserOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionRecloser not available for addition to VendorDistributionPole entity."));
            }


            //create an object to hold the collection for addition to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionRecloserEntity> NewCollection;
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionRecloserEntity>(args.DataSetFromDataBase.Tables[3],args.UseCheckSum);


            //redeclare and cast the argument result colection
            ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity> ResultCollection;
            ResultCollection = (ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity>)args.CollectionToReturn;


            //loop through each entity in the resulting collection
            foreach (VendorDistributionPoleEntity ParentEntity in ResultCollection)
            {
                //create an entity that will be used to filter
                VendorDistributionRecloserEntity filterEntity = new VendorDistributionRecloserEntity();
                filterEntity.Vendor_Distribution_PoleFk = ParentEntity.Vendor_Distribution_Poles_PoleId;


                //create a filtered collection and add it to the entity
                ParentEntity.VendorDistributionRecloserCollection = NewCollection.Filter(filterEntity, ProjectCommon2.Enumerations.FilterOperator.And);

            }

        }

        #endregion
		
        #region Start VendorDistributionRecloser Transactions Event Handlers
		
		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionRecloserCollectionBeginHandler(object sender, Classes.Bases.BeforeSaveCollectionBeginEventArgs args)
        {

            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }

        }

		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionRecloserEntityBeginHandler(object sender, Classes.Bases.BeforeSaveEntityBeginEventArgs args)
        {
            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }
        }

        #endregion

		#region Insert/Update/Delete VendorDistributionRecloser Event Handlers
		
		/// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />
		/// event. Responsible for deleting all child VendorDistributionRecloser Entities from the database before the 
		/// parent VendorDistributionPoleEntity is deleted.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeEntityDeleteEventArgs" />.</param>
		/// <remarks>
		/// <para>Sets the deletion mark for every VendorDistributionRecloserEntity in the child collection to
		/// <c>true</c> by calling the collection's 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;.SetAllIsMarkedToDelete(bool)" /> method.
		/// Then it deletes the collection by sending it to the VendorDistributionRecloserFactory's
		/// <see cref="Factories.VendorDistributionRecloserFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionRecloserEntity&gt;, bool)" />
		/// method.</para>
		/// </remarks>
        static void OnBeforeVendorDistributionRecloserEntityDeleteHandler(object sender, Classes.Bases.BeforeEntityDeleteEventArgs args)
        {

			//redeclare and cast the argument delete entity
            VendorDistributionPoleEntity DeleteEntity;
            DeleteEntity = (VendorDistributionPoleEntity)args.EntityToDelete;

			//make sure the child collection is actually used
			if (DeleteEntity.VendorDistributionRecloserCollection == null)
				return;

            //mark all child entities of the parent entity to delete
            DeleteEntity.VendorDistributionRecloserCollection.SetAllIsMarkedToDelete(true);

            //delete all the notes
            VendorDistributionRecloserFactory.Save(DeleteEntity.VendorDistributionRecloserCollection, args.UseCheckSum);

        }

        /// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />
		/// event. Responsible for saving (which may mean inserting/updating/deleting) all child VendorDistributionRecloser Entities
		/// to the database before the parent VendorDistributionPoleEntity is saved.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveEntityCommitEventArgs" />.</param>
		/// <remarks>
		/// <para>Saves every VendorDistributionRecloserEntity in the child collection by sending it to the VendorDistributionRecloserFactory's
		/// <see cref="Factories.VendorDistributionRecloserFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionRecloserEntity&gt;, bool)" />
		/// method.
		/// </para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionRecloserEntityCommitHandler(object sender, Classes.Bases.BeforeSaveEntityCommitEventArgs args)
        {

			//redeclare and cast the argument save entity
            VendorDistributionPoleEntity EntityToSave;
            EntityToSave = (VendorDistributionPoleEntity)args.EntityToSave;

			//make sure the child collection is actually used
			if (EntityToSave.VendorDistributionRecloserCollection == null)
				return;


            // loop through each entity in the VendorDistributionRecloser collection
            foreach (VendorDistributionRecloserEntity ChildEntity in EntityToSave.VendorDistributionRecloserCollection)
            {
                //For Saftey set the FK for all the child entities
				ChildEntity.Vendor_Distribution_PoleFk = EntityToSave.Vendor_Distribution_Poles_PoleId;
				

            }

            // insert/update/delete all the child eities
            VendorDistributionRecloserFactory.Save(EntityToSave.VendorDistributionRecloserCollection, args.UseCheckSum);

        }

        #endregion
		
 		#endregion
		
		#region Event Handlers: VendorDistributionInspectionResult 
		
		/// <summary>
        /// Stores the number that indicates the order of the VendorDistributionInspectionResult table in the
		/// DataSet returned by the Factory's <c>Get()</c> methods. 
        /// </summary>
		/// <remarks>This number is used by the <see cref="OnAfterGetVendorDistributionInspectionResultEntityHandler" />
		/// and the <see cref="OnAfterGetVendorDistributionInspectionResultCollectionHandler" /> methods to determine
		/// if the VendorDistributionInspectionResult table exists in the DataSet. This number was
		/// determined at the time the code was generated.
		/// </remarks>
		private const int VendorDistributionInspectionResultOrdinalPosition = 4;
		
		#region Get VendorDistributionInspectionResult Event Handlers

		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntity" /> event. Fills a collection 
		/// with <c>VendorDistributionInspectionResult</c> Entities and adds it to the VendorDistributionPoleEntity passed in the event
		/// argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionInspectionResult
		/// table from which the VendorDistributionInspectionResult Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entity to which the collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> using data from the 
		/// DataSet passed in the event argument and then assigns it to the
		/// <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionInspectionResultCollection" /> property of the
		/// VendorDistributionPoleEntity being retrieved (also passed in the event argument).</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionInspectionResultEntityHandler(object sender, Classes.Bases.AfterGetEntityEventArgs args)
        {

            //ensure that the dataset contains the second datatable constaining
            //the VendorDistributionInspectionResult data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionInspectionResultOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionInspectionResult not available for addition to VendorDistributionPole entity; The factory event handler found that there is no member ordinally placed in the dataset datatable collection."));
            }


            //redeclare and cast the argument result entity 
            VendorDistributionPoleEntity EntityToReturn;
            EntityToReturn = (VendorDistributionPoleEntity)args.EntityToReturn;

			//ensure the entity is created
			if (EntityToReturn == null)
				return;

            //create an object to generate the collection for addition
            //to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionInspectionResultEntity> NewCollection;

            //fill the collection with the datatable
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionInspectionResultEntity>(args.DataSetFromDataBase.Tables[VendorDistributionInspectionResultOrdinalPosition],args.UseCheckSum);

            //add the collection to the entity
            EntityToReturn.VendorDistributionInspectionResultCollection = NewCollection;

        }
		
		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntityCollection" /> event. Adds a collection 
		/// of <c>VendorDistributionInspectionResult</c> Entities to each VendorDistributionPoleEntity in the collection passed in the 
		/// event argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionInspectionResult
		/// table from which the VendorDistributionInspectionResult Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entities to which a VendorDistributionInspectionResult collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> and fills it with VendorDistributionInspectionResult
		/// Entities from the VendorDistributionInspectionResult data contained in the DataSet passed in the event argument. It then filters
		/// this collection for each VendorDistributionPoleEntity (according to the Vendor_Distribution_Poles_PoleId
		/// property), and assigns the result to the <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionInspectionResultCollection" />
		/// property of each VendorDistributionPoleEntity.</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionInspectionResultCollectionHandler(object sender, Classes.Bases.AfterGetEntityCollectionEventArgs args)
        {
            //ensure that the dataset contains the second datatable constaining
            //the Document Tracking notes data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionInspectionResultOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionInspectionResult not available for addition to VendorDistributionPole entity."));
            }


            //create an object to hold the collection for addition to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionInspectionResultEntity> NewCollection;
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionInspectionResultEntity>(args.DataSetFromDataBase.Tables[4],args.UseCheckSum);


            //redeclare and cast the argument result colection
            ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity> ResultCollection;
            ResultCollection = (ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity>)args.CollectionToReturn;


            //loop through each entity in the resulting collection
            foreach (VendorDistributionPoleEntity ParentEntity in ResultCollection)
            {
                //create an entity that will be used to filter
                VendorDistributionInspectionResultEntity filterEntity = new VendorDistributionInspectionResultEntity();
                filterEntity.Vendor_Distribution_PoleFk = ParentEntity.Vendor_Distribution_Poles_PoleId;


                //create a filtered collection and add it to the entity
                ParentEntity.VendorDistributionInspectionResultCollection = NewCollection.Filter(filterEntity, ProjectCommon2.Enumerations.FilterOperator.And);

            }

        }

        #endregion
		
        #region Start VendorDistributionInspectionResult Transactions Event Handlers
		
		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionInspectionResultCollectionBeginHandler(object sender, Classes.Bases.BeforeSaveCollectionBeginEventArgs args)
        {

            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }

        }

		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionInspectionResultEntityBeginHandler(object sender, Classes.Bases.BeforeSaveEntityBeginEventArgs args)
        {
            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }
        }

        #endregion

		#region Insert/Update/Delete VendorDistributionInspectionResult Event Handlers
		
		/// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />
		/// event. Responsible for deleting all child VendorDistributionInspectionResult Entities from the database before the 
		/// parent VendorDistributionPoleEntity is deleted.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeEntityDeleteEventArgs" />.</param>
		/// <remarks>
		/// <para>Sets the deletion mark for every VendorDistributionInspectionResultEntity in the child collection to
		/// <c>true</c> by calling the collection's 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;.SetAllIsMarkedToDelete(bool)" /> method.
		/// Then it deletes the collection by sending it to the VendorDistributionInspectionResultFactory's
		/// <see cref="Factories.VendorDistributionInspectionResultFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionInspectionResultEntity&gt;, bool)" />
		/// method.</para>
		/// </remarks>
        static void OnBeforeVendorDistributionInspectionResultEntityDeleteHandler(object sender, Classes.Bases.BeforeEntityDeleteEventArgs args)
        {

			//redeclare and cast the argument delete entity
            VendorDistributionPoleEntity DeleteEntity;
            DeleteEntity = (VendorDistributionPoleEntity)args.EntityToDelete;

			//make sure the child collection is actually used
			if (DeleteEntity.VendorDistributionInspectionResultCollection == null)
				return;

            //mark all child entities of the parent entity to delete
            DeleteEntity.VendorDistributionInspectionResultCollection.SetAllIsMarkedToDelete(true);

            //delete all the notes
            VendorDistributionInspectionResultFactory.Save(DeleteEntity.VendorDistributionInspectionResultCollection, args.UseCheckSum);

        }

        /// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />
		/// event. Responsible for saving (which may mean inserting/updating/deleting) all child VendorDistributionInspectionResult Entities
		/// to the database before the parent VendorDistributionPoleEntity is saved.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveEntityCommitEventArgs" />.</param>
		/// <remarks>
		/// <para>Saves every VendorDistributionInspectionResultEntity in the child collection by sending it to the VendorDistributionInspectionResultFactory's
		/// <see cref="Factories.VendorDistributionInspectionResultFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionInspectionResultEntity&gt;, bool)" />
		/// method.
		/// </para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionInspectionResultEntityCommitHandler(object sender, Classes.Bases.BeforeSaveEntityCommitEventArgs args)
        {

			//redeclare and cast the argument save entity
            VendorDistributionPoleEntity EntityToSave;
            EntityToSave = (VendorDistributionPoleEntity)args.EntityToSave;

			//make sure the child collection is actually used
			if (EntityToSave.VendorDistributionInspectionResultCollection == null)
				return;


            // loop through each entity in the VendorDistributionInspectionResult collection
            foreach (VendorDistributionInspectionResultEntity ChildEntity in EntityToSave.VendorDistributionInspectionResultCollection)
            {
                //For Saftey set the FK for all the child entities
				ChildEntity.Vendor_Distribution_PoleFk = EntityToSave.Vendor_Distribution_Poles_PoleId;
				

            }

            // insert/update/delete all the child eities
            VendorDistributionInspectionResultFactory.Save(EntityToSave.VendorDistributionInspectionResultCollection, args.UseCheckSum);

        }

        #endregion
		
 		#endregion
		
		#region Event Handlers: VendorDistributionSectionalizer 
		
		/// <summary>
        /// Stores the number that indicates the order of the VendorDistributionSectionalizer table in the
		/// DataSet returned by the Factory's <c>Get()</c> methods. 
        /// </summary>
		/// <remarks>This number is used by the <see cref="OnAfterGetVendorDistributionSectionalizerEntityHandler" />
		/// and the <see cref="OnAfterGetVendorDistributionSectionalizerCollectionHandler" /> methods to determine
		/// if the VendorDistributionSectionalizer table exists in the DataSet. This number was
		/// determined at the time the code was generated.
		/// </remarks>
		private const int VendorDistributionSectionalizerOrdinalPosition = 5;
		
		#region Get VendorDistributionSectionalizer Event Handlers

		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntity" /> event. Fills a collection 
		/// with <c>VendorDistributionSectionalizer</c> Entities and adds it to the VendorDistributionPoleEntity passed in the event
		/// argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionSectionalizer
		/// table from which the VendorDistributionSectionalizer Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entity to which the collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> using data from the 
		/// DataSet passed in the event argument and then assigns it to the
		/// <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionSectionalizerCollection" /> property of the
		/// VendorDistributionPoleEntity being retrieved (also passed in the event argument).</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionSectionalizerEntityHandler(object sender, Classes.Bases.AfterGetEntityEventArgs args)
        {

            //ensure that the dataset contains the second datatable constaining
            //the VendorDistributionSectionalizer data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionSectionalizerOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionSectionalizer not available for addition to VendorDistributionPole entity; The factory event handler found that there is no member ordinally placed in the dataset datatable collection."));
            }


            //redeclare and cast the argument result entity 
            VendorDistributionPoleEntity EntityToReturn;
            EntityToReturn = (VendorDistributionPoleEntity)args.EntityToReturn;

			//ensure the entity is created
			if (EntityToReturn == null)
				return;

            //create an object to generate the collection for addition
            //to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionSectionalizerEntity> NewCollection;

            //fill the collection with the datatable
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionSectionalizerEntity>(args.DataSetFromDataBase.Tables[VendorDistributionSectionalizerOrdinalPosition],args.UseCheckSum);

            //add the collection to the entity
            EntityToReturn.VendorDistributionSectionalizerCollection = NewCollection;

        }
		
		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntityCollection" /> event. Adds a collection 
		/// of <c>VendorDistributionSectionalizer</c> Entities to each VendorDistributionPoleEntity in the collection passed in the 
		/// event argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionSectionalizer
		/// table from which the VendorDistributionSectionalizer Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entities to which a VendorDistributionSectionalizer collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> and fills it with VendorDistributionSectionalizer
		/// Entities from the VendorDistributionSectionalizer data contained in the DataSet passed in the event argument. It then filters
		/// this collection for each VendorDistributionPoleEntity (according to the Vendor_Distribution_Poles_PoleId
		/// property), and assigns the result to the <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionSectionalizerCollection" />
		/// property of each VendorDistributionPoleEntity.</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionSectionalizerCollectionHandler(object sender, Classes.Bases.AfterGetEntityCollectionEventArgs args)
        {
            //ensure that the dataset contains the second datatable constaining
            //the Document Tracking notes data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionSectionalizerOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionSectionalizer not available for addition to VendorDistributionPole entity."));
            }


            //create an object to hold the collection for addition to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionSectionalizerEntity> NewCollection;
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionSectionalizerEntity>(args.DataSetFromDataBase.Tables[5],args.UseCheckSum);


            //redeclare and cast the argument result colection
            ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity> ResultCollection;
            ResultCollection = (ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity>)args.CollectionToReturn;


            //loop through each entity in the resulting collection
            foreach (VendorDistributionPoleEntity ParentEntity in ResultCollection)
            {
                //create an entity that will be used to filter
                VendorDistributionSectionalizerEntity filterEntity = new VendorDistributionSectionalizerEntity();
                filterEntity.Vendor_Distribution_PoleFk = ParentEntity.Vendor_Distribution_Poles_PoleId;


                //create a filtered collection and add it to the entity
                ParentEntity.VendorDistributionSectionalizerCollection = NewCollection.Filter(filterEntity, ProjectCommon2.Enumerations.FilterOperator.And);

            }

        }

        #endregion
		
        #region Start VendorDistributionSectionalizer Transactions Event Handlers
		
		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionSectionalizerCollectionBeginHandler(object sender, Classes.Bases.BeforeSaveCollectionBeginEventArgs args)
        {

            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }

        }

		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionSectionalizerEntityBeginHandler(object sender, Classes.Bases.BeforeSaveEntityBeginEventArgs args)
        {
            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }
        }

        #endregion

		#region Insert/Update/Delete VendorDistributionSectionalizer Event Handlers
		
		/// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />
		/// event. Responsible for deleting all child VendorDistributionSectionalizer Entities from the database before the 
		/// parent VendorDistributionPoleEntity is deleted.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeEntityDeleteEventArgs" />.</param>
		/// <remarks>
		/// <para>Sets the deletion mark for every VendorDistributionSectionalizerEntity in the child collection to
		/// <c>true</c> by calling the collection's 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;.SetAllIsMarkedToDelete(bool)" /> method.
		/// Then it deletes the collection by sending it to the VendorDistributionSectionalizerFactory's
		/// <see cref="Factories.VendorDistributionSectionalizerFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionSectionalizerEntity&gt;, bool)" />
		/// method.</para>
		/// </remarks>
        static void OnBeforeVendorDistributionSectionalizerEntityDeleteHandler(object sender, Classes.Bases.BeforeEntityDeleteEventArgs args)
        {

			//redeclare and cast the argument delete entity
            VendorDistributionPoleEntity DeleteEntity;
            DeleteEntity = (VendorDistributionPoleEntity)args.EntityToDelete;

			//make sure the child collection is actually used
			if (DeleteEntity.VendorDistributionSectionalizerCollection == null)
				return;

            //mark all child entities of the parent entity to delete
            DeleteEntity.VendorDistributionSectionalizerCollection.SetAllIsMarkedToDelete(true);

            //delete all the notes
            VendorDistributionSectionalizerFactory.Save(DeleteEntity.VendorDistributionSectionalizerCollection, args.UseCheckSum);

        }

        /// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />
		/// event. Responsible for saving (which may mean inserting/updating/deleting) all child VendorDistributionSectionalizer Entities
		/// to the database before the parent VendorDistributionPoleEntity is saved.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveEntityCommitEventArgs" />.</param>
		/// <remarks>
		/// <para>Saves every VendorDistributionSectionalizerEntity in the child collection by sending it to the VendorDistributionSectionalizerFactory's
		/// <see cref="Factories.VendorDistributionSectionalizerFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionSectionalizerEntity&gt;, bool)" />
		/// method.
		/// </para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionSectionalizerEntityCommitHandler(object sender, Classes.Bases.BeforeSaveEntityCommitEventArgs args)
        {

			//redeclare and cast the argument save entity
            VendorDistributionPoleEntity EntityToSave;
            EntityToSave = (VendorDistributionPoleEntity)args.EntityToSave;

			//make sure the child collection is actually used
			if (EntityToSave.VendorDistributionSectionalizerCollection == null)
				return;


            // loop through each entity in the VendorDistributionSectionalizer collection
            foreach (VendorDistributionSectionalizerEntity ChildEntity in EntityToSave.VendorDistributionSectionalizerCollection)
            {
                //For Saftey set the FK for all the child entities
				ChildEntity.Vendor_Distribution_PoleFk = EntityToSave.Vendor_Distribution_Poles_PoleId;
				

            }

            // insert/update/delete all the child eities
            VendorDistributionSectionalizerFactory.Save(EntityToSave.VendorDistributionSectionalizerCollection, args.UseCheckSum);

        }

        #endregion
		
 		#endregion
		
		#region Event Handlers: VendorDistributionTransformer 
		
		/// <summary>
        /// Stores the number that indicates the order of the VendorDistributionTransformer table in the
		/// DataSet returned by the Factory's <c>Get()</c> methods. 
        /// </summary>
		/// <remarks>This number is used by the <see cref="OnAfterGetVendorDistributionTransformerEntityHandler" />
		/// and the <see cref="OnAfterGetVendorDistributionTransformerCollectionHandler" /> methods to determine
		/// if the VendorDistributionTransformer table exists in the DataSet. This number was
		/// determined at the time the code was generated.
		/// </remarks>
		private const int VendorDistributionTransformerOrdinalPosition = 6;
		
		#region Get VendorDistributionTransformer Event Handlers

		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntity" /> event. Fills a collection 
		/// with <c>VendorDistributionTransformer</c> Entities and adds it to the VendorDistributionPoleEntity passed in the event
		/// argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionTransformer
		/// table from which the VendorDistributionTransformer Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entity to which the collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> using data from the 
		/// DataSet passed in the event argument and then assigns it to the
		/// <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionTransformerCollection" /> property of the
		/// VendorDistributionPoleEntity being retrieved (also passed in the event argument).</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionTransformerEntityHandler(object sender, Classes.Bases.AfterGetEntityEventArgs args)
        {

            //ensure that the dataset contains the second datatable constaining
            //the VendorDistributionTransformer data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionTransformerOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionTransformer not available for addition to VendorDistributionPole entity; The factory event handler found that there is no member ordinally placed in the dataset datatable collection."));
            }


            //redeclare and cast the argument result entity 
            VendorDistributionPoleEntity EntityToReturn;
            EntityToReturn = (VendorDistributionPoleEntity)args.EntityToReturn;

			//ensure the entity is created
			if (EntityToReturn == null)
				return;

            //create an object to generate the collection for addition
            //to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionTransformerEntity> NewCollection;

            //fill the collection with the datatable
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionTransformerEntity>(args.DataSetFromDataBase.Tables[VendorDistributionTransformerOrdinalPosition],args.UseCheckSum);

            //add the collection to the entity
            EntityToReturn.VendorDistributionTransformerCollection = NewCollection;

        }
		
		/// <summary>
        /// Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnAfterGetEntityCollection" /> event. Adds a collection 
		/// of <c>VendorDistributionTransformer</c> Entities to each VendorDistributionPoleEntity in the collection passed in the 
		/// event argument object.
		/// </summary>
		/// <exception cref="ProjectCommon2.Exceptions.MissingDataTableException">Thrown if the VendorDistributionTransformer
		/// table from which the VendorDistributionTransformer Collection will be filled does not exist in the DataSet 
		/// contained in the event argument. Thrown using 
		/// <see cref="ProjectCommon2.Helpers.ExceptionHelper.Throw(System.Exception)"/>, which controls
		/// exception handling activities.
		/// </exception>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.AfterGetEntityEventArgs" />, as it contains the DataSet to fill the 
		/// collection with, and the Entities to which a VendorDistributionTransformer collection will be added.</param>
		/// <remarks>
		/// <para>This method creates a new 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;" /> and fills it with VendorDistributionTransformer
		/// Entities from the VendorDistributionTransformer data contained in the DataSet passed in the event argument. It then filters
		/// this collection for each VendorDistributionPoleEntity (according to the Vendor_Distribution_Poles_PoleId
		/// property), and assigns the result to the <see cref="Classes.Entities.VendorDistributionPoleEntity.VendorDistributionTransformerCollection" />
		/// property of each VendorDistributionPoleEntity.</para>
		/// </remarks>
        static void OnAfterGetVendorDistributionTransformerCollectionHandler(object sender, Classes.Bases.AfterGetEntityCollectionEventArgs args)
        {
            //ensure that the dataset contains the second datatable constaining
            //the Document Tracking notes data
            if (args.DataSetFromDataBase.Tables.Count < VendorDistributionTransformerOrdinalPosition + 1)
            {
                ProjectCommon2.Helpers.ExceptionHelper.Throw(new ProjectCommon2.Exceptions.MissingDataTableException("VendorDistributionTransformer not available for addition to VendorDistributionPole entity."));
            }


            //create an object to hold the collection for addition to the entity 
            ProjectCommon2.Generics.EntityCollection< VendorDistributionTransformerEntity> NewCollection;
            NewCollection = new ProjectCommon2.Generics.EntityCollection< VendorDistributionTransformerEntity>(args.DataSetFromDataBase.Tables[6],args.UseCheckSum);


            //redeclare and cast the argument result colection
            ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity> ResultCollection;
            ResultCollection = (ProjectCommon2.Generics.EntityCollection< VendorDistributionPoleEntity>)args.CollectionToReturn;


            //loop through each entity in the resulting collection
            foreach (VendorDistributionPoleEntity ParentEntity in ResultCollection)
            {
                //create an entity that will be used to filter
                VendorDistributionTransformerEntity filterEntity = new VendorDistributionTransformerEntity();
                filterEntity.Vendor_Distribution_PoleFk = ParentEntity.Vendor_Distribution_Poles_PoleId;


                //create a filtered collection and add it to the entity
                ParentEntity.VendorDistributionTransformerCollection = NewCollection.Filter(filterEntity, ProjectCommon2.Enumerations.FilterOperator.And);

            }

        }

        #endregion
		
        #region Start VendorDistributionTransformer Transactions Event Handlers
		
		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveCollectionBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionTransformerCollectionBeginHandler(object sender, Classes.Bases.BeforeSaveCollectionBeginEventArgs args)
        {

            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }

        }

		/// <summary>Handler for the <see cref="Classes.Factories.VendorDistributionPoleFactory.OnBeforeSaveEntityBegin" />
		/// event. Responsible for notifying the VendorDistributionPoleFactory that originated the event if a transaction should
		/// be started.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveCollectionBeginEventArgs" />.</param>
		/// <remarks>
		/// <para>This method checks the <see cref="ProjectCommon2.Helpers.TransactionManager.IsInTransaction" />
		/// property of the static <c>TransactionManager</c> to see if a transaction has been already started, if not, it
		/// sets the <see cref="Bases.BeforeSaveCollectionBeginEventArgs.BeginTransaction" /> property of the event argument
		/// to <c>true</c>. This property is checked by the Factory upon resuming the Save operation to determine if it should
		/// start a new transaction.</para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionTransformerEntityBeginHandler(object sender, Classes.Bases.BeforeSaveEntityBeginEventArgs args)
        {
            //if not already in a transaction then start one
            if (!ProjectCommon2.Helpers.TransactionManager.IsInTransaction)
            {
                args.BeginTransaction = true;
            }
        }

        #endregion

		#region Insert/Update/Delete VendorDistributionTransformer Event Handlers
		
		/// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeEntityDelete" />
		/// event. Responsible for deleting all child VendorDistributionTransformer Entities from the database before the 
		/// parent VendorDistributionPoleEntity is deleted.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeEntityDeleteEventArgs" />.</param>
		/// <remarks>
		/// <para>Sets the deletion mark for every VendorDistributionTransformerEntity in the child collection to
		/// <c>true</c> by calling the collection's 
		/// <see cref="ProjectCommon2.Generics.EntityCollection&lt;EntityType&gt;.SetAllIsMarkedToDelete(bool)" /> method.
		/// Then it deletes the collection by sending it to the VendorDistributionTransformerFactory's
		/// <see cref="Factories.VendorDistributionTransformerFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionTransformerEntity&gt;, bool)" />
		/// method.</para>
		/// </remarks>
        static void OnBeforeVendorDistributionTransformerEntityDeleteHandler(object sender, Classes.Bases.BeforeEntityDeleteEventArgs args)
        {

			//redeclare and cast the argument delete entity
            VendorDistributionPoleEntity DeleteEntity;
            DeleteEntity = (VendorDistributionPoleEntity)args.EntityToDelete;

			//make sure the child collection is actually used
			if (DeleteEntity.VendorDistributionTransformerCollection == null)
				return;

            //mark all child entities of the parent entity to delete
            DeleteEntity.VendorDistributionTransformerCollection.SetAllIsMarkedToDelete(true);

            //delete all the notes
            VendorDistributionTransformerFactory.Save(DeleteEntity.VendorDistributionTransformerCollection, args.UseCheckSum);

        }

        /// <summary>Handler for the <see cref="VendorDistributionPoleFactory.OnBeforeSaveEntityCommit" />
		/// event. Responsible for saving (which may mean inserting/updating/deleting) all child VendorDistributionTransformer Entities
		/// to the database before the parent VendorDistributionPoleEntity is saved.</summary>
		/// <param name="sender">The object that raised the event.</param>
        /// <param name="args">The object containing data about the event; must be of type 
		/// <see cref="Bases.BeforeSaveEntityCommitEventArgs" />.</param>
		/// <remarks>
		/// <para>Saves every VendorDistributionTransformerEntity in the child collection by sending it to the VendorDistributionTransformerFactory's
		/// <see cref="Factories.VendorDistributionTransformerFactory.Save(ProjectCommon2.Generics.EntityCollection&lt;Classes.Entities.VendorDistributionTransformerEntity&gt;, bool)" />
		/// method.
		/// </para>
		/// </remarks>
        static void OnBeforeSaveVendorDistributionTransformerEntityCommitHandler(object sender, Classes.Bases.BeforeSaveEntityCommitEventArgs args)
        {

			//redeclare and cast the argument save entity
            VendorDistributionPoleEntity EntityToSave;
            EntityToSave = (VendorDistributionPoleEntity)args.EntityToSave;

			//make sure the child collection is actually used
			if (EntityToSave.VendorDistributionTransformerCollection == null)
				return;


            // loop through each entity in the VendorDistributionTransformer collection
            foreach (VendorDistributionTransformerEntity ChildEntity in EntityToSave.VendorDistributionTransformerCollection)
            {
                //For Saftey set the FK for all the child entities
				ChildEntity.Vendor_Distribution_PoleFk = EntityToSave.Vendor_Distribution_Poles_PoleId;
				

            }

            // insert/update/delete all the child eities
            VendorDistributionTransformerFactory.Save(EntityToSave.VendorDistributionTransformerCollection, args.UseCheckSum);

        }

        #endregion
		
 		#endregion
		
	}
}